package com.midea.leetcode;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @description：
 * @author: wangwl23
 * 全排列问题
 * 回溯法
 * @create: 2021-03-17 11:41
 */
public class FullPermutation {

    static List<List<Integer>> res = new ArrayList<>();
    public static void main(String[] args) {
        permute(new int[]{1,2,3});
    }
    private static List<List<Integer>> permute(int[] nums){
        LinkedList<Integer> track = new LinkedList<>();
        backtrack(nums,track);
        System.out.println(res);
        return res;
    }

    private static void backtrack(int[] nums, LinkedList<Integer> track) {
        if (track.size() == nums.length){
            res.add(new LinkedList<>(track));
            return;
        }
        for (int i = 0;i<nums.length;i++){
            if(track.contains(nums[i])){
                continue;
            }
            track.add(nums[i]);
            backtrack(nums,track);
            //track.remove(nums[i]);
            track.removeLast();
        }
    }
}
